#include<iostream>
#include<stdlib.h>

using namespace std;
class stack{
    public:
    stack()
    {
        _array=(int *)malloc(sizeof(int )*10);
        _capacity=10;
        _top=0;
    }
    ~stack()
    {
        free(_array);
        _top=_capacity=0;
    }
    void push(int val)
    {
        CheckCapacity();
        _array[_top++]=val;
    }
    void pop()
    {
        if(_top>0)_top--;
    }
    int Top()
    {
        if(_top==0)return -1;
        return _array[_top-1];
    }
    bool Empty()
    {
        return _top==0;
    }
    int Size()
    {
        return _top;
    }
    private:
    void CheckCapacity()
    {
        if(_top==_capacity)
        {
            _array=(int *)realloc(_array,sizeof(int)*_capacity*2);
            _capacity*=2;
        }
    }
    int *_array;
    int _capacity;
    int _top;
};
int main()
{
    stack s1;
    s1.push(1);
    s1.push(2);
    s1.push(3);
    s1.push(4);
    cout<<"size="<<s1.Size()<<endl;
    cout<<"top="<<s1.Top()<<endl;
    if(s1.Empty())cout<<"stack is empty！"<<endl;
    s1.push(5); 
    s1.push(6);
    s1.pop();
    s1.pop();
    s1.pop();
    s1.pop();
    s1.pop();
    s1.pop();
    if(s1.Empty())cout<<"stack is empty！"<<endl;
    return 0;
}
